package com.lwj.liwanjia.presenter;

import com.lwj.liwanjia.bean.LoginBean;
import com.lwj.liwanjia.impl.LoginView;
import com.lwj.liwanjia.model.LoginModel;

import rx.Subscriber;

/**
 * 登录
 */

public class LoginPresenter {
    private LoginView loginView;
    private LoginModel loginModel;

    public LoginPresenter(LoginView loginView) {
        this.loginView = loginView;
        loginModel = new LoginModel();
    }

    public void getToken(String name, String password) {
        if (loginView != null) {
            loginModel.getToken(name, password, new Subscriber<LoginBean>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {
                    loginView.showError((Exception) e);
                }

                @Override
                public void onNext(LoginBean loginBean) {
                    loginView.getToken(loginBean);
                }
            });
        }
    }
}
